﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using DataAccess.Config;
using System.Data;
namespace Bussiness.Config
{
    public class ConfigBLL
    {
        private ConfigDAL dal;
        public ConfigBLL()
        {
            dal = new ConfigDAL();
        }
        public FOModels.Config.Config getConfigKey(string key)
        {
            FOModels.Config.Config config = null;
            DataTable tb = dal.getConfigKey(key);
            if (tb != null)
            {
                config = new FOModels.Config.Config();
                config.Ckey = tb.Rows[0]["Ckey"].ToString();
                config.Cvalue = tb.Rows[0]["CValues"].ToString();
            }
            return config;
        }
        public Dictionary<string,FOModels.Config.Config> getConfigListkey (string[] key)
        {
            DataTable tb = dal.getConfigList(key);
            FOModels.Config.Config cftemp = null;
            Dictionary<string, FOModels.Config.Config> list = new Dictionary<string, FOModels.Config.Config>();
            if (tb != null)
            {
                foreach (DataRow row in tb.Rows)
                {
                    cftemp = new FOModels.Config.Config();
                    cftemp.Ckey = row["Ckey"].ToString();
                    cftemp.Cvalue = row["CValues"].ToString();
                    list.Add(cftemp.Ckey,cftemp);
                }
            }
            return list;
        }
        public Dictionary<string, FOModels.Config.Config> getConfigGroup(string groupName)
        {
            Dictionary<string, FOModels.Config.Config> list = new  Dictionary<string,FOModels.Config.Config>();
            DataTable tb = dal.getConfigGroup(groupName);
            FOModels.Config.Config cftem;
            if (tb != null)
            {
                foreach (DataRow dr in tb.Rows)
                {
                    cftem = new FOModels.Config.Config();
                    cftem.Ckey = dr[0].ToString();
                    cftem.Cvalue = dr[1].ToString();
                    cftem.GroupName = dr[2].ToString();
                    list.Add(cftem.Ckey,cftem);
                }
            }
            return list;
        }
    }
}
